

export function toLoginPage(redirect=true) {
	let page = Router.page.user.login;

	if (redirect) {
		page += "?target=" + location.pathname + location.search
	}

	toPage(page);
}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 



export function toSize(byteSize) {
	const flag = ["B", "KB", "MB", "GB", "TB", "PB"];

	// 1GB = 1L << 30
    // x / 1024 <=> x >> 10
    let count = 0;
    let temp = byteSize * 10;

    while ((temp >> 10) >= 10) {
        count++;

        temp = temp >> 10;
    }


    let s = temp / 10;
    let l = temp % 10;

    if (count > 2 && 0 != l) {
        return s + "." + l + flag[count];
    }
    return s + flag[count];
}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 



export function addDataFmt() {
	Date.prototype.format = function(fmt) {
		const o = {
			"M+" : this.getMonth() + 1,					//月份
			"d+" : this.getDate(),						//日
			"h+" : this.getHours(),						//小时
			"m+" : this.getMinutes(),					//分
			"s+" : this.getSeconds(),					//秒
			"q+" : Math.floor((this.getMonth()+3) / 3),	//季度
			"S"  : this.getMilliseconds()				//毫秒
		};
	
	
		let temp = fmt;
	
		if(/(y+)/.test(temp)){
			temp = temp.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
		}
	
		for(let k in o){
			if(new RegExp("("+ k +")").test(temp)){
				temp = temp.replace(
					RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));  
			}
		}
	
		return temp;
	}
}

